//
//  QMAAppEnvironmentDelegateImp.m
//  QQMiniGameSDKDemo
//
//  Created by Goyoungs on 2023/4/14.
//

#import "QMAAppEnvironmentDelegateImp.h"
#import <AdSupport/AdSupport.h>
#import "AppDelegate.h"
@interface QMAAppEnvironmentDelegateImp ()
@end

@implementation QMAAppEnvironmentDelegateImp

- (instancetype)init {
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kReachabilityChangedNotification object:nil];
    }
    return self;
}

- (void)networkStateChange {
    //，网络变化通知，需要通知给小游戏
    [[NSNotificationCenter defaultCenter] postNotificationName:@"miniAppNetWorkChanged" object:nil];
}

/// SDK宿主应用名称
/// 主要用于文案提示使用
- (nonnull NSString *)appName {
    //TODO: 宿主替换
    return @"九四玩游戏";
}

/// SDK宿主平台设备信息
/// 格式 model=***&os=***&display=***&ifa=***&idfa=***
- (nonnull NSString *)getAppDeviceInfo { 
    static NSString *model = nil;
    static NSString *os = nil;
    static NSString *display = nil;
    static NSString *ifv = nil;
    static NSString *ifa = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        model = [[UIDevice currentDevice] model];
        os = [NSString stringWithFormat:@"iOS/%@", [[UIDevice currentDevice] systemVersion]];
        
        display = [NSString stringWithFormat:@"%f*%f", ([UIScreen mainScreen].bounds.size.width * [UIScreen mainScreen].scale),
                   ([UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale)];
        ifv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        ifa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    });
    
    NSString *devInfo = [NSString stringWithFormat:@"model=%@&os=%@&display=%@&ifa=%@&idfa=%@", model, os, display, ifv, ifa];
    
    return devInfo;
}

/// SDK宿主平台的机型信息
- (nonnull NSString *)getAppIPhoneModel { 
    return @"iPhone";
}

/// SDK宿主平台的网络状态
- (QMANetWorkStatus)getAppNetworkStatus {
    //TODO: 宿主替换
    NetworkStatus netStatus = [(AppDelegate *)[UIApplication sharedApplication].delegate currentStatus];
    switch (netStatus) {
        case ReachableViaWiFi:
            return QMANetWorkStatus_ReachableViaWiFi;
        case ReachableViaWWAN:
            return QMANetWorkStatus_ReachableVia4G;
        case NotReachable:
            return QMANetWorkStatus_NotReachable;
        default:
            break;
    }
    return QMANetWorkStatus_Unknown;
}

/// SDK宿主平台QUA
/// 格式:  "V1_IPH_MINISDK_" + version + "_1_" + hostPlatform +"_B"
/// 如果是微视接入，V1_IPH_MINISDK_1.0.0_1_WEISHI_B
/// 版本号后面的是app包的标识，1 是appstore包，3是灰度包，5是众测包
- (nonnull NSString *)getAppQUA {
    //TODO: 宿主替换
    return @"V1_IPH_SQ_8.2.6_0_RDM_R";
}

/// SDK宿主平台版本
/// 返回的是小写字符串，例如1.0.0
- (nonnull NSString *)getAppVersion { 
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}

/// SDK宿主平台的idfa
- (nonnull NSString *)idfa { 
    return @"";
}

/// SDK宿主平台的idfa
- (nonnull NSString *)imei { 
    return @"";
}

/// SDK宿主IP协议栈类型，默认IPv4和IPv6双栈
- (QMAIPStackType)ipStackType { 
    return QMAIPStackType_IPv4_IPv6;
}

/// SDK宿主平台的gps信息
/// NSDictionary
/// key："longitude" 和 "latitude"，
/// value:：CLLocationCoordinate2D中的longitude和latitude
- (nonnull NSDictionary *)lbsModelLocation { 
    NSDictionary *result = @{@"longitude" : @"", @"latitude" : @""};
    return result;
}

/// SDK宿主平台的本地ip
- (nonnull NSString *)localIP { 
    return @"";
}

/// 新版qimei,SDK宿主平台的QImei36
- (nonnull NSString *)qimei36 { 
    return @"";
}

/// SDK宿主平台的WifiBSSID
- (nonnull NSString *)wifiBSSID { 
    return @"";
}

/// SDK宿主平台的用户账号来源
- (QMASourceUinPlatform)getAppUIDPlatform {
    //TODO: 宿主替换
    return QMASourceUinPlatformQQ;
}


@end
